package meiju;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.apache.commons.lang3.EnumUtils;
import org.junit.Test;

import java.util.Objects;

/**
 * 测试枚举类
 */
public class TestMeiJu {

    public static void main(String[] args) {
        MessageStateEnum a = MessageStateEnum.OK_ELEMENT;
        //needEnum(a);
        MessageStateEnum b = MessageStateEnum.toEnum("error");
        System.out.println(b);//ERROR_ELEMENT
        String status = MessageStateEnum.getStatus(11);
        System.out.println(status);//ok
    }

    @Test
    public void test01(){
        boolean result = EnumUtils.isValidEnum(MessageStateEnum.class,"ERROR_ELEMENT");
        System.out.println(result);
        MessageStateEnum error_element = MessageStateEnum.valueOf("ERROR_ELEMENT");
        System.out.println(error_element.getStatus());
    }

    @Test
    public void test02(){
        String name = StatusEnum.OK.name();
        System.out.println(name);
        Integer ok = StatusEnum.getCode("OK");
        System.out.println(ok);
    }

    @Test
    public void test03(){
        System.out.println(Objects.equals("OK", StatusEnum.OK));
    }

    @Test
    public void test04(){
        StatusEnum ok = StatusEnum.valueOf("OK");
        System.out.println(ok);
        StatusEnum ok1 = StatusEnum.valueOf("ok"); //valueOf如果输入非法的枚举类型会报错!!!
        System.out.println(ok1);
    }

    private static void needEnum(MessageStateEnum mse){
        System.out.println(mse);//OK_ELEMENT (枚举变量的名称) -> String类型
        System.out.println(mse.getNum());//11
        System.out.println(mse.getStatus());//ok
        /* 枚举对象的==和equals方式是一个作用看源码可知 */
        if(mse == MessageStateEnum.OK_ELEMENT){
            System.out.println("true");
        }else{
            System.out.println("false");
        }
    }

}
